package com.cn.controller.newList;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cn.entity.TbNews;
import com.cn.service.newList.TbNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Author zxl
 * @Date 2021/6/3 14:37
 * @Package com.controller
 * @Version 1.0
 */

@Controller
@RequestMapping("/newsList")
public class TbNewsController {



    @Autowired
    public TbNewsService tbNewsService;

    @RequestMapping("/selectAllTbNews")
    public String selectAllTbNews(Model model){
        IPage<TbNews> tbNewsIPage = tbNewsService.selectAllTbNews(1);
        model.addAttribute("pages",tbNewsIPage);
        return "/newsList/saved_resource";
    }

    @RequestMapping("/addTbNews")
    public String addTbNews(TbNews tbNews){
        int i = tbNewsService.addTbNews(tbNews);
        if(i!=0){
            return "1";
        }else {
            return "1";
        }

    }

    @RequestMapping("/updateTbNewsById")
    public String updateTbNewsById(TbNews tbNews){
        int i = tbNewsService.updateTbNewsById(tbNews);
        if(i!=0){
            return "1";
        }else {
            return "1";
        }
    }

    @RequestMapping("/deleteTbNewsById")
    public String daleteTbNewsById(int id){
        int i = tbNewsService.deleteTbNewsById(id);
        if(i!=0){
            return "1";
        }else {
            return "1";
        }
    }


}
